<template>
  <div class="app-container home">
    

    <!-- 管理模块快捷入口 -->
    <el-row :gutter="20" class="management-modules">
      <el-col :xs="8" :sm="6" :md="4" :lg="3" class="module-item">
        <div class="module-card" @click="goToModule('/business/user')">
          <div class="module-icon user-icon">
            <i class="el-icon-user"></i>
          </div>
          <div class="module-title">用户管理</div>
        </div>
      </el-col>
      <el-col :xs="8" :sm="6" :md="4" :lg="3" class="module-item">
        <div class="module-card" @click="goToModule('/business/group')">
          <div class="module-icon log-icon">
            <i class="el-icon-document-copy"></i>
          </div>
          <div class="module-title">群组管理</div>
        </div>
      </el-col>
      <el-col :xs="8" :sm="6" :md="4" :lg="3" class="module-item">
        <div class="module-card" @click="goToModule('/business/messages')">
          <div class="module-icon message-icon">
            <i class="el-icon-message"></i>
          </div>
          <div class="module-title">消息管理</div>
        </div>
      </el-col>
      <el-col :xs="8" :sm="6" :md="4" :lg="3" class="module-item">
        <div class="module-card" @click="goToModule('/business/sensitiveword')">
          <div class="module-icon sensitive-icon">
            <i class="el-icon-document"></i>
          </div>
          <div class="module-title">敏感词管理</div>
        </div>
      </el-col>
      <el-col :xs="8" :sm="6" :md="4" :lg="3" class="module-item">
        <div class="module-card" @click="goToModule('/business/robot')">
          <div class="module-icon robot-icon">
            <i class="el-icon-cpu"></i>
          </div>
          <div class="module-title">机器人管理</div>
        </div>
      </el-col>
      <el-col :xs="8" :sm="6" :md="4" :lg="3" class="module-item">
        <div class="module-card" @click="goToModule('/business/report')">
          <div class="module-icon monitor-icon">
            <i class="el-icon-monitor"></i>
          </div>
          <div class="module-title">举报管理</div>
        </div>
      </el-col>
      <el-col :xs="8" :sm="6" :md="4" :lg="3" class="module-item">
        <div class="module-card" @click="goToModule('/business/channel')">
          <div class="module-icon channel-icon">
            <i class="el-icon-connection"></i>
          </div>
          <div class="module-title">频道管理</div>
        </div>
      </el-col>
      <el-col :xs="8" :sm="6" :md="4" :lg="3" class="module-item">
        <div class="module-card" @click="goToModule('/system/config')">
          <div class="module-icon config-icon">
            <i class="el-icon-setting"></i>
          </div>
          <div class="module-title">系统管理</div>
        </div>
      </el-col>
    </el-row>

 <!-- 统计卡片 -->
    <el-row :gutter="20" class="panel-group">
      <el-col :xs="12" :sm="12" :md="6" :lg="6" :xl="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-description">
            <div class="card-panel-text">平台总人数</div>
            <div class="card-panel-num">{{ indexData.toDayCount || 0 }}</div>
            <div class="card-panel-sub">昨日数据 <span class="data-value">{{ indexData.yesterDayCount || 0 }}</span></div>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :md="6" :lg="6" :xl="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-description">
            <div class="card-panel-text">今日注册用户</div>
            <div class="card-panel-num">{{ indexData.toDayRegisterCount || 0 }}</div>
            <div class="card-panel-sub">昨日数据 <span class="data-value">{{ indexData.yesterDayRegisterCount || 0 }}</span></div>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :md="6" :lg="6" :xl="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-description">
            <div class="card-panel-text">在线用户</div>
            <div class="card-panel-num">{{ indexData.onlineCount || 0 }}</div>
            <div class="card-panel-sub">实时数据</div>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :md="6" :lg="6" :xl="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-description">
            <div class="card-panel-text">群组数量</div>
            <div class="card-panel-num">{{ indexData.groupCount || 0 }}</div>
            <div class="card-panel-sub">总计数量</div>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :md="6" :lg="6" :xl="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-description">
            <div class="card-panel-text">敏感词命中数</div>
            <div class="card-panel-num">{{ indexData.sensitiveWordHitCount || 0 }}</div>
            <div class="card-panel-sub">今日统计</div>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :md="6" :lg="6" :xl="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-description">
            <div class="card-panel-text">机器人数量</div>
            <div class="card-panel-num">{{ indexData.robotCount || 0 }}</div>
            <div class="card-panel-sub">活跃机器人</div>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :md="6" :lg="6" :xl="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-description">
            <div class="card-panel-text">举报数量</div>
            <div class="card-panel-num">{{ indexData.reportCount || 0 }}</div>
            <div class="card-panel-sub">待处理举报</div>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :md="6" :lg="6" :xl="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-description">
            <div class="card-panel-text">频道数量</div>
            <div class="card-panel-num">{{ indexData.channelCount || 0 }}</div>
            <div class="card-panel-sub">总计频道</div>
          </div>
        </div>
      </el-col>
    </el-row>
    
  </div>
</template>

<script>
import { getIndexInfo } from '@/api/system/index'

export default {
  name: "Index",
  data() {
    return {
      version: "3.9.0",
      indexData: {
        toDayCount: 0,
        yesterDayCount: 0,
        toDayRegisterCount: 0,
        yesterDayRegisterCount: 0,
        onlineCount: 0,
        groupCount: 0,
        sensitiveWordHitCount: 0,
        yesterDaySensitiveWordHitCount: 0,
        robotCount: 0,
        yesterDayRobotCount: 0,
        reportCount: 0,
        yesterDayReportCount: 0,
        channelCount: 0,
        yesterDayChannelCount: 0
      },
      loading: false
    }
  },
  created() {
    this.getIndexData()
  },
  methods: {
    goTarget(href) {
      window.open(href, "_blank")
    },
    goToModule(path) {
      this.$router.push(path)
    },
    // 获取首页统计数据
    getIndexData() {
      this.loading = true
      getIndexInfo().then(response => {
        this.indexData = response.data
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    }
  }
}
</script>

<style scoped lang="scss">
.home {
  background: #f0f2f5;
  min-height: 100vh;
  padding: 20px;
  
  // 统计卡片样式
  .panel-group {
    margin-bottom: 20px;
    
    .card-panel-col {
      margin-bottom: 20px;
    }

    .card-panel {
      background: #fff;
      border-radius: 4px;
      padding: 20px;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
      border: 1px solid #e8e8e8;
      
      .card-panel-description {
        .card-panel-text {
          font-size: 14px;
          color: #666;
          margin-bottom: 8px;
        }

        .card-panel-num {
          font-size: 28px;
          font-weight: 600;
          color: #333;
          margin-bottom: 8px;
        }

        .card-panel-sub {
          font-size: 12px;
          color: #999;
          
          .data-value {
            color: #409EFF;
            font-weight: 500;
          }
        }
      }
    }
  }

  // 管理模块样式
  .management-modules {
    margin-bottom: 20px;
    
    .module-item {
      margin-bottom: 16px;
    }

    .module-card {
      background: #fff;
      border-radius: 4px;
      padding: 16px;
      text-align: center;
      cursor: pointer;
      transition: all 0.3s ease;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
      border: 1px solid #e8e8e8;
      height: 80px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;

      &:hover {
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
        transform: translateY(-2px);
      }

      .module-icon {
        font-size: 24px;
        margin-bottom: 8px;
        width: 32px;
        height: 32px;
        border-radius: 6px;
        display: flex;
        align-items: center;
        justify-content: center;
        
        &.user-icon {
          background: #e3f2fd;
          color: #2196f3;
        }
        
        &.message-icon {
          background: #f3e5f5;
          color: #9c27b0;
        }
        
        &.sensitive-icon {
          background: #fff3e0;
          color: #ff9800;
        }
        
        &.robot-icon {
          background: #e8f5e8;
          color: #4caf50;
        }
        
        &.channel-icon {
          background: #fce4ec;
          color: #e91e63;
        }
        
        &.config-icon {
          background: #f1f8e9;
          color: #8bc34a;
        }
        
        &.monitor-icon {
          background: #e0f2f1;
          color: #009688;
        }
        
        &.log-icon {
          background: #fff8e1;
          color: #ffc107;
        }
      }

      .module-title {
        font-size: 12px;
        color: #333;
        font-weight: 500;
        line-height: 1.2;
      }
    }
  }

  // 图表区域样式
  .chart-section {
    .chart-container {
      background: #fff;
      border-radius: 4px;
      padding: 20px;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
      border: 1px solid #e8e8e8;
      margin-bottom: 20px;
      
      .chart-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 16px;
        
        h3 {
          margin: 0;
          font-size: 16px;
          font-weight: 600;
          color: #333;
        }
        
        .chart-controls {
          .el-button {
            margin-left: 8px;
          }
        }
      }
      
      .chart-legend {
        margin-bottom: 16px;
        
        .legend-item {
          margin-right: 20px;
          font-size: 12px;
          color: #666;
          
          .legend-dot {
            display: inline-block;
            width: 8px;
            height: 8px;
            border-radius: 50%;
            margin-right: 6px;
            
            &.blue {
              background: #409EFF;
            }
            
            &.orange {
              background: #E6A23C;
            }
          }
        }
      }
      
      .chart-content {
        height: 200px;
        
        .chart-placeholder {
          height: 100%;
          display: flex;
          align-items: flex-end;
          justify-content: center;
          
          .chart-bars {
            display: flex;
            align-items: flex-end;
            height: 100%;
            width: 80%;
            
            .bar {
              flex: 1;
              background: linear-gradient(to top, #409EFF, #66b1ff);
              margin: 0 2px;
              border-radius: 2px 2px 0 0;
              min-height: 20px;
            }
          }
          
          .line-chart {
            width: 100%;
            height: 100%;
          }
        }
      }
    }
  }
}
</style>

<style scoped>
/* 图表容器等高、内容自适应 */
.chart-container {
  display: flex;
  flex-direction: column;
  height: 360px; /* 两个图表统一高度 */
}

.chart-content {
  flex: 1;
  display: flex;
}

.chart-placeholder {
  flex: 1;
  display: flex;
}

.chart-bars {
  height: 100%;
  display: flex;
  align-items: flex-end; /* 柱子从底部对齐 */
}

.line-chart {
  height: 100%;
}

.line-chart svg {
  height: 100%;
  width: 100%;
}

/* 可选：小屏适配降低一点高度 */
@media (max-width: 768px) {
  .chart-container {
    height: 300px;
  }
}

/* 你已有的样式保留在此注释上下 */
</style>

